package idoc.index;

public  class BytesUtil {

	static byte[] toBytes(int val) {

		byte[] bb = new byte[4];
		for (int i = 0; i < bb.length; i++) {
			bb[i] = (byte) (val >> (bb.length - i - 1) * 8);
		}
		return bb;

	}

	static int toInt(byte[] bb) {

		int i = 0;
		for (int k = 0; k < bb.length; k++) {
			i |= ((long) bb[k] & 255) << (bb.length - k - 1) * 8;
		}
		return i;

	}

	static long toLong(byte[] bb) {

		long l = 0;
		for (int i = 0; i < 8; i++) {
			l |= ((long) bb[i] & 255) << (bb.length - i - 1) * 8;
		}
		return l;

	}

	static byte[] toBytes(long number) {

		byte[] bb = new byte[8];
		for (int i = 0; i < bb.length; i++) {
			bb[i] = (byte) (number >> (bb.length - i - 1) * 8);
		}
		return bb;

	}

}
